package Day15.ZuoYe;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

//客户端选择要查询的类型，是气温，还是其他，服务端返回相应的值，并加上当前的日期（用yyyy-MM-dd hh:mm:ss格式），
//服务端通过多线程的方式提高性能,客户端发送和接收统一采用字符串格式
public class WeatherClient {
    public static void main(String[] args) {
        Socket socket = null;
        Scanner input = new Scanner(System.in);
        try {
//            socket = new Socket("127.0.0.1", 9999);
//            System.out.println("已连接服务器。。。。。。");
            while (true) {
                socket = new Socket("127.0.0.1", 9999);
                System.out.println("请输入您需要查询的天气内容（exit退出）：\n气温，风力，pm2.5，湿度");
                String st = input.next();
                if (st.equals("exit")) {
                    System.out.println("退出！");
                    return;
                }
                OutputStream os = socket.getOutputStream();
                PrintWriter pw = new PrintWriter(os, true);
                pw.println(st);
                InputStream is = socket.getInputStream();
                BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
                String s = buffer.readLine();
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
